﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE;
using ProcedureList.Library.Domain;

namespace SSMSProcedureList
{
    internal class CacheItem
    {
        string _lastText = null;
        IList<MethodDto> _lastMethods;
        public IList<MethodDto> GetMethods(string text)
        {
            if (text != _lastText)
            {
                var scanner = new DocumentScanner(text);
                var scannerController = new DocumentProcedureUIController(scanner);
                _lastMethods = scannerController.GetMethods();
            }
            return _lastMethods;
        }
    }

    internal class Cache
    {
        private Dictionary<Window, CacheItem> _cache = new Dictionary<Window, CacheItem>();

        public IList<MethodDto> GetMethods(Window window, string text)
        {
            if (!_cache.ContainsKey(window))
            {
                _cache[window] = new CacheItem();
            }
            return _cache[window].GetMethods(text);
        }
    }
}
